<script setup>
import { ref } from 'vue'

import { User, Lock } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import request from '@/utils/request'
import { showNotify } from '@nutui/nutui'
import { useLoginUserStore } from '@/stores'
const { setLoginUserInfo } = useLoginUserStore()
const router = useRouter()
const form = ref()
//整个用于提交的form数据对象
const formModel = ref({
  username: '',
  password: '',
  repassword: ''
})
const rules = ref({
  username: [
    { required: true, message: '请输入手机号', trigger: 'blur' },
    { min: 11, max: 11, message: '手机号必须是11位的字符', trigger: 'blur' },
    {
      pattern: /^1[3456789]\d{9}$/,
      message: '手机号格式不正确',
      trigger: 'blur'
    }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    {
      pattern: /^\S{6,15}$/,
      message: '密码必须是 6-15位 的非空字符',
      trigger: 'blur'
    }
  ],
  repassword: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    {
      pattern: /^\S{6,15}$/,
      message: '密码必须是 6-15位 的非空字符',
      trigger: 'blur'
    },
    {
      validator: (rule, value, callback) => {
        // 判断 value 和当前 form 中收集的password 是否一致
        if (value !== formModel.value.password) {
          callback(new Error('两次输入密码不一致'))
        } else {
          callback() //就算成功也要 callback
        }
      },
      trigger: 'blur'
    }
  ]
})
const goToAboutPage = async () => {
  //router.push('/clocking-in/Clock') //下面这块空掉就是伪登陆
  await form.value.validate()
  request({
    url: '/login',
    method: 'get',
    params: {
      loginName: formModel.value.username,
      password: formModel.value.password
    }
  }).then((res) => {
    if (res.code == 0) {
      showNotify.success('登录成功')
      setLoginUserInfo(res.data)
      router.push('/clocking-in/Clock')
    }
  })
}
</script>

<template>
  <div class="container">
    <div class="biaodan">
      <div class="title">
        <h1>欢迎登陆</h1>
      </div>
    </div>
    <div class="loginDiv">
      <el-form
        class="loginFrom"
        :model="formModel"
        :rules="rules"
        ref="form"
        size="large"
        autocomplete="off"
      >
        <el-form-item prop="username">
          <el-input
            class="input1"
            v-model="formModel.username"
            :prefix-icon="User"
            placeholder="手机号   +86"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            class="input2"
            v-model="formModel.password"
            :prefix-icon="Lock"
            type="password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>

    <div class="biaodan btn_login">
      <button @click="goToAboutPage">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span>登陆</span>
      </button>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container {
  /* 设置背景图 */
  background-image: url('./src/assets/photo/kun1.PNG');
  /* 设置背景图填充方式，这里是平铺 */
  background-repeat: repeat;
  /* 设置背景图尺寸，这里是 cover */
  background-size: cover;
  /* 设置背景图位置，这里是居中 */
  background-position: center;
  /* 设置容器高度，确保背景图可以完全显示 */
  min-height: 100vh;
  .loginDiv {
    width: 100%;
    display: flex;
    justify-content: center;
    .loginFrom {
      width: 60%;
    }
  }
}
/* 表单 */
.biaodan {
  display: flex;
  justify-content: center;
  align-items: center;
}

.title {
  margin-top: 50px;
  font-size: 1.1em;
}

.input1[type='text'] {
  display: block;
  color: rgb(34, 34, 34);
  background: linear-gradient(
    142.99deg,
    rgba(217, 217, 217, 1) 15.53%,
    rgba(243, 243, 243, 0.8) 88.19%
  );
  box-shadow: 0px 12px 24px -1px rgba(70, 255, 255, 0.18);
  border-color: rgba(7, 4, 14, 0);
  border-radius: 50px;
  block-size: 20px;
  margin: 7px auto;
  padding: 18px 15px;
  outline: none;
  text-align: center;
  width: 200px;
  transition: 0.5s;
  margin-top: 40px;
}

.input1[type='text']:hover {
  width: 240px;
}

.input1[type='text']:focus {
  width: 280px;
}

.input2[type='text'] {
  display: block;
  color: rgb(34, 34, 34);
  background: linear-gradient(
    142.99deg,
    rgba(217, 217, 217, 1) 15.53%,
    rgba(243, 243, 243, 0.8) 88.19%
  );
  box-shadow: 0px 12px 24px -1px rgba(70, 255, 255, 0.18);
  border-color: rgba(7, 4, 14, 0);
  border-radius: 50px;
  block-size: 20px;
  margin: 7px auto;
  padding: 18px 15px;
  outline: none;
  text-align: center;
  width: 200px;
  transition: 0.5s;
  margin-top: 20px;
}

.input2[type='text']:hover {
  width: 240px;
}

.input2[type='text']:focus {
  width: 280px;
}

/* 为什么鼠标悬停用不了 */
.input:hover {
  background-color: white;
  transform: scale(1.05);
  box-shadow:
    13px 13px 100px #969696,
    -13px -13px 100px #ffffff;
}

.input2:focus {
  background-color: white;
  transform: scale(1.05);
  box-shadow:
    13px 13px 100px #969696,
    -13px -13px 100px #ffffff;
}

/* 按钮样式 */
button {
  transform: rotate(-25deg) skew(25deg);
  transform-style: preserve-3d;
  position: relative;
  top: -200px;
  list-style: none;
  width: 100px;
  height: 32px;
  border: none;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  margin-top: 600px;
}

button:before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: -5px;
  width: 100%;
  height: 10px;
  background: #2a2a2a;
  transform: skewX(-41deg);
}

button:after {
  content: '';
  position: absolute;
  top: 5px;
  left: -9px;
  width: 9px;
  height: 100%;
  background: #2a2a2a;
  transform: skewY(-49deg);
}

button span {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #2a2a2a;
  color: #fff;
  font-size: 25px;
  transition: 1s ease-out;
}

button:hover span {
  z-index: 1000;
  transition: 0.3s;
  color: #fff;
}

button:hover span:nth-child(5) {
  transform: translate(40px, -40px);
  opacity: 1;
}

button:hover span:nth-child(4) {
  transform: translate(30px, -30px);
  opacity: 0.8;
}

button:hover span:nth-child(3) {
  transform: translate(20px, -20px);
  opacity: 0.6;
}

button:hover span:nth-child(2) {
  transform: translate(10px, -10px);
  opacity: 0.4;
}

button:hover span:nth-child(1) {
  transform: translate(0px, 0px);
  opacity: 0.2;
}

button:active span:nth-child(5) {
  transform: translate(20px, -20px);
  opacity: 1;
}

button:active span:nth-child(4) {
  transform: translate(15px, -15px);
}

button:active span:nth-child(3) {
  transform: translate(10px, -10px);
}

button:active span:nth-child(2) {
  transform: translate(5px, -5px);
}

button:active span:nth-child(1) {
  transform: translate(0px, 0px);
}

button:nth-child(1):hover span {
  background: #000000;
}
</style>
